precision mediump float;

uniform sampler2D u_grass;

varying vec2 v_uv; 
varying vec4 v_color;
varying float v_eyeDist;

float computeLinearFogFactor()
{
   float factor;
   
   // Compute linear fog equation
   factor = (100.0 - v_eyeDist) / 80.0;
   
   // Clamp in the [0,1] range
   factor = clamp(factor, 0.0, 1.0);
            
   return factor;            
}
void main()
{
	float fogFactor = computeLinearFogFactor();
    vec4 u_fogColor = vec4(1.0, 1.0, 1.0, 1.0);

	vec4 grassColor = texture2D(u_grass, v_uv); 
	gl_FragColor = v_color * grassColor * fogFactor + u_fogColor  * (1.0 - fogFactor);
}